Skip to content

643 sse heartbeat 적용#644

Merged
ByunDohwi merged 3 commits intodevelopfrom
643-sse-heartbeat-적용
Jan 27, 2026

Hidden character warning

The head ref may contain hidden characters: "643-sse-heartbeat-\uc801\uc6a9"
Merged

643 sse heartbeat 적용#644
ByunDohwi merged 3 commits intodevelopfrom
643-sse-heartbeat-적용

Conversation

@ByunDohwi
Copy link
Member

@ByunDohwi ByunDohwi commented Jan 27, 2026

  • emitter에 생명주기를 추가했습니다. onError와 onTimeout에 반응하여 emitter를 제거합니다.
  • 30초를 주기로 모든 emitter에 요청을 보내 연결을 지속합니다.

Summary by CodeRabbit

릴리스 노트

  • 새로운 기능

    • SSE 하트비트 기능이 추가되어 평일 08:00~21:59에 30초마다 연결을 유지합니다.
  • 버그 수정

    • 클라이언트 연결 해제(브로큰 파이프 등) 감지 및 처리 로직을 개선했습니다.
    • 네트워크 오류 발생 시 에러 처리 및 연결/리소스 정리 동작이 강화되었습니다.

✏️ Tip: You can customize this high-level summary in your review settings.

@ByunDohwi ByunDohwi self-assigned this Jan 27, 2026
@ByunDohwi ByunDohwi added the 기능 개발 API 개발 label Jan 27, 2026
@ByunDohwi ByunDohwi linked an issue Jan 27, 2026 that may be closed by this pull request
@coderabbitai
Copy link

coderabbitai bot commented Jan 27, 2026

Walkthrough

스케줄러가 평일 08:00–21:59 사이 30초 간격으로 SseRegistryPort.sendHeartbeat()를 호출하도록 ScheduleService에 의존성 및 작업을 추가했고, SseRegistry에 emitters 대상 하트비트 전송·에러/종료 처리 로직과 registerEmitterCallbacks 유틸이 도입되었습니다.

Changes

Cohort / File(s) Summary
스케줄링 변경
src/main/kotlin/dsm/pick2024/infrastructure/schedule/ScheduleService.kt
SseRegistryPort 의존성 추가 및 평일 08:00–21:59 30초 간격 sseHeartbeat 스케줄 작업 추가 (sendHeartbeat() 호출)
SSE 레지스트리 구현 변경
src/main/kotlin/dsm/pick2024/infrastructure/sse/SseRegistry.kt
sendHeartbeat() 메서드 추가(모든 emitter에 heartbeat 전송), registerEmitterCallbacks() 도입으로 onCompletion/onTimeout/onError 정리 통합, 클라이언트 중단 감지(isClientAbort) 및 에러 처리 개선
포트 인터페이스 확장
src/main/kotlin/dsm/pick2024/infrastructure/sse/port/out/SseRegistryPort.kt
fun sendHeartbeat() 메서드 시그니처 추가 (구현 필요)

Sequence Diagram(s)

sequenceDiagram
    actor Scheduler as Scheduler
    participant ScheduleService
    participant SseRegistryPort
    participant SseRegistry
    participant Emitter

    Scheduler->>ScheduleService: sseHeartbeat 트리거<br/>(평일 08:00–21:59, 30초마다)
    ScheduleService->>SseRegistryPort: sendHeartbeat()
    SseRegistryPort->>SseRegistry: sendHeartbeat()
    SseRegistry->>SseRegistry: 등록된 emitters 반복
    SseRegistry->>Emitter: send("heartbeat" event)
    alt 전송 성공
        Emitter-->>SseRegistry: 성공 확인
    else 전송 실패 (클라이언트 중단)
        Emitter-->>SseRegistry: ClientAbortException / Broken pipe
        SseRegistry->>SseRegistry: completeWithError 및 emitter 제거
    else 전송 실패 (기타 오류)
        Emitter-->>SseRegistry: IOException 등
        SseRegistry->>SseRegistry: 로그 기록 및 emitter 제거
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

하트비트를 두근두근 보내요 🐇
삼십 초마다 소식 전하고,
끊긴 선은 살며시 정리해요.
작은 토끼가 지키는 연결,
오늘도 안정적으로 뛰어가네 ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 8.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 제목 '643 sse heartbeat 적용'은 풀 리퀘스트의 주요 변경사항인 SSE 하트비트 기능 추가를 명확하게 요약하고 있습니다.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai
Copy link

coderabbitai bot commented Jan 27, 2026

Note

Docstrings generation - SUCCESS
Generated docstrings for this pull request at #645

coderabbitai bot added a commit that referenced this pull request Jan 27, 2026
Docstrings generation was requested by @ByunDohwi.

* #644 (comment)

The following files were modified:

* `src/main/kotlin/dsm/pick2024/infrastructure/schedule/ScheduleService.kt`
* `src/main/kotlin/dsm/pick2024/infrastructure/sse/SseRegistry.kt`
* `src/main/kotlin/dsm/pick2024/infrastructure/sse/port/out/SseRegistryPort.kt`
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/main/kotlin/dsm/pick2024/infrastructure/sse/SseRegistry.kt`:
- Around line 73-76: onError 핸들러에서 emitter.complete()를 호출하면 이미
completeWithError()로 완료 중인 emitter에 대해 중복 호출이 발생할 수 있으므로 emitter.onError { ... }
내부에서 complete() 호출을 제거하고 cleanup만 수행하도록 변경하세요; 구체적으로 SseRegistry.kt의
emitter.onError 콜백에서 emitter.complete()를 삭제하고 cleanup.run()만 남기며 에러 상황은
completeWithError(error) 호출부에서만 처리되도록 유지하세요.
🧹 Nitpick comments (1)
src/main/kotlin/dsm/pick2024/infrastructure/sse/SseRegistry.kt (1)

39-47: 중복 cleanup 호출 가능성.

completeWithError(e)를 호출하면 registerEmitterCallbacks()에서 등록된 onError 콜백이 트리거되어 이미 remove()가 호출됩니다. 이후 명시적인 remove() 호출은 중복입니다.

또한 isClientAbort() 분기 로직이 로깅 외에는 동일하므로 간소화할 수 있습니다.

♻️ 제안된 리팩토링
             try {
                 emitter.send(SseEmitter.event().data(data ?: "."))
             } catch (e: Exception) {
-                if (isClientAbort(e)) {
-                    emitter.completeWithError(e)
-                    remove(userId, emitter)
-                    continue
+                if (!isClientAbort(e)) {
+                    logger.error("User Event Send Failed ${e.message}", e)
                 }
-                logger.error("User Event Send Failed ${e.message}", e)
                 emitter.completeWithError(e)
-                remove(userId, emitter)
+                // onError 콜백에서 cleanup이 자동으로 처리됨
             }

@ByunDohwi ByunDohwi merged commit 32e93ed into develop Jan 27, 2026
2 checks passed
@ByunDohwi ByunDohwi deleted the 643-sse-heartbeat-적용 branch January 27, 2026 07:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

기능 개발 API 개발

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SSE heartbeat 적용

2 participants